Skip to content

fix(cli): preview answers unknown paths with an inert refusal, not the Studio shell - #8161

Merged
Vitozhu04 merged 2 commits into
mainfrom
claude/secops-2642-preview-catchall-a574f4
Nov 20, 2026
Merged

Vitozhu04 merged 2 commits into
mainfrom
claude/secops-2642-preview-catchall-a574f4

Conversation

@Vitozhu04

@Vitozhu04 Vitozhu04 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

hyperframes preview answered every unknown GET with the Studio shell (200, same origin, query kept). An OAuth redirect to the preview port (/oauth/callback?code=…&state=…) therefore re-mounted the project, and project script read the code from the address.

Studio routes by location.hash only, so it never needs a path:

  • The shell is served only at / and /index.html. /assets/*, /icons/*, /favicon.svg, /api/* and /__hyperframes_config are unchanged.
  • Any other path, for any method, gets a plain-text 404 Not found..
  • A request carrying code or state at any path gets a plain-text 400. That includes / and /api/projects/:id/preview, which loads project script. This runs as the first middleware. No Studio route uses either parameter.
  • Vite-served modes (dev mode from a source checkout, and local studio / HYPERFRAMES_LOCAL_STUDIO=1) run packages/studio/vite.config.ts, whose SPA fallback also served the shell at /oauth/callback?code=…. devProjectApi now refuses a code or state at any path as its first middleware, before every route and Vite's own fallback. Unknown paths there still reach Vite, which serves source modules at many paths, so these modes get the OAuth-return refusal but no path allowlist.
  • Under /api/* the API sub-app answers unknown paths itself (a plain-text or JSON 404, no sandbox). No return reaches it, because the code/state refusal runs first.
  • Both refusals send a fixed body and never echo the request. Their headers: Content-Type: text/plain, X-Content-Type-Options: nosniff, a CSP of sandbox; default-src 'none'; frame-ancestors 'none', X-Frame-Options: DENY, Cross-Origin-Opener-Policy: same-origin, Cross-Origin-Resource-Policy: same-origin, Referrer-Policy: no-referrer, Cache-Control: no-store. The CSP sandbox gives the page an opaque origin, so a same-origin opener or parent cannot read its address. COOP alone leaves a same-origin popup readable. The helper now lives in @hyperframes/studio-server (helpers/inertRefusal.ts), so the embedded server and the Vite modes share it. The part 3 copy in fix(cli): play and present answer unknown paths with an inert refusal #8160 (utils/strayRequestRefusal.ts) has already drifted: it answers 404 and sends no CORP. Follow-up: once both PRs land, move fix(cli): play and present answer unknown paths with an inert refusal #8160 onto this helper so the header set has one owner.

The CLI's own login (packages/cli/src/auth/loopback.ts) runs its own node:http server on an ephemeral port and is untouched. src/auth tests pass.

No visible change

The only non-test change under packages/studio is 6 lines in vite.config.ts: a dev-server middleware that answers a request carrying code or state with a plain-text refusal. Studio's UI, its normal loads, and the player don't change.

Tests

New packages/cli/src/server/studioServer.unknownPaths.test.ts:

  • /oauth/callback and /callback with code and state, on 127.0.0.1 and localhost, plus four unknown paths. Each must be non-HTML with the headers above and must not contain the code, the state, < or the shell.
  • code and/or state on /, /index.html and /api/projects/project/preview, and on a POST.
  • The entry routes /, /index.html and /?hf_canary_… still serve the shell.

packages/studio/vite.config.hosts.test.ts, "studio dev server OAuth returns": /oauth/callback, /callback, /, /index.html and /api/projects/project/preview, each with code or state, must get the inert 400 from the plugin's middleware, with no SECRET in the body. A plain /?hf_canary_… must still pass through to Vite.

Fails without the fix: studioServer.unknownPaths.test.ts. 13 of 16 tests fail against main's studioServer.ts. For example, "refuses an OAuth return at /oauth/callback instead of serving the Studio shell" gets expected 200 to be greater than or equal to 400, and the preview-route and POST cases get expected null to be 'nosniff'. The 3 entry-route tests pass on both. Also vite.config.hosts.test.ts "studio dev server OAuth returns": all 5 refusal cases fail without the middleware. The page routes get expected undefined to be 400, because they pass through to Vite's fallback; the preview route gets expected 200 to be 400.

Two existing tests assumed the shell at a made-up SPA path (/editor, /projects/demo). They now hit /index.html.

Related changes (not in this PR)

Residual (not this PR)

A return in the fragment (/#code=) never reaches the server, so no server-side check can refuse it. The code grant always answers in the query. Whether the CLI client can be issued an implicit-grant (fragment) response is part 4's to close.

Verification

  • vitest run for src/server + src/auth: all pass, apart from the known-flaky fileWatcher.atomic real-FS test, which passes on rerun.
  • Full cli suite: 7 failures. All of them also fail against main's studioServer.ts on this machine (openWritesNothing is flaky and passed with the fix): whisper/manager-resolution, utils/projectLock, utils/publishProject (Unicode form), commands/lambda/deploy (warming), checkSweep.chromium ×2 (WebGL).
  • tsc --noEmit, oxlint, oxfmt, fallow and comment-ratchet are clean.
  • 966e80223: studio-server 2154 passed; Studio vite.* 89 passed; CLI src/server + src/auth 413 passed. tsc is clean for studio-server, studio and cli, and the comment ratchet passes.
  • Browser behaviour at 4956762f was checked by a reviewer in Chrome 155: all 12 popup and iframe reads that succeed on main are blocked. I have not run a browser against the Vite modes; their test drives the plugin's middleware chain directly.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 73 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 9910e9eb15df4b6d4ed8c037fea02622d7ad4f4d.

studioServer.ts:998 rejects code/state queries before all routes, including project preview and non-GET requests. The shell now has only its two entry routes; the fixed refusal never reflects request input. The CSP sandbox supplies opaque-origin protection in addition to framing denial and COOP. The legitimate login listener is a separate server and remains unchanged.

Validation: full workspace build passed. Through pytest-gate.sh, the unknown-path, static-asset, file-race and auth tests passed 268/268. Replacing only studioServer.ts with its base version gives 13 failures / 3 passes in the 16 new regressions. Restored afterward. Independent adversarial source audit found no blocker. Preview was tested through its actual Hono app; I did not run a live preview/browser login flow.

Nit: after the play/present change lands, consolidate server/inertRefusal.ts and utils/strayRequestRefusal.ts into one shared query predicate/header policy, preserving the intentionally different status/body contracts. They currently duplicate the same security policy.

Need: yes · Size: ok · Reuse: existing Hono boundary and URLSearchParams · Simpler: focused entry-route allowlist · Structure: consolidate sibling refusal helpers after both land
Risk: medium — local browser security boundary.

Verdict: APPROVE
Reasoning: Query-bearing returns cannot reach project code, unknown paths no longer remount the shell, and legitimate entry/login tests remain green. This is the query-return mitigation, not general origin separation.

— Rames / hf-review

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 9910e9eb, against main (merge base 7930525; merges clean with current main ed3f05a and with #8160). Rames already covered the server-side behavior and the helper duplication; this adds a browser run and the one preview mode the fix doesn't reach.

What holds up

  • studioServer.ts:999 runs before every other middleware and route, so code/state is refused on every path and method, /api/* included. I sent 23 request variants through the app: /index.html?code=, /?code=, /oauth/callback/?code=, %63ode, a bare ?code, a duplicate code, //oauth/callback?code=, /assets/../oauth/callback?code=, /assets/x.js?code=, /__hyperframes_config?code=, /api/runtime.js?code=, /api/projects/project/preview/index.html?state=, and HEAD and OPTIONS. Every one got the inert 400 with the full header set and a fixed body, and none echoed the request. %2563ode, CODE and a=1;code= still get the shell, but the authorization server always writes a literal code= key, so none of those can carry a real return.
  • I ran it in Chrome 155 against a real server. The attacker page was the project's own preview document (/api/projects/project/preview). Iframe and popup, direct and through a cross-origin 302, to /oauth/callback, /, /index.html and the project preview path. On main all 12 reads returned …?code=SECRET. On this head every popup is severed and every frame is unreadable. The PR body says no browser run was done, so this fills that gap.
  • inertRefusal.ts:2-11: sandbox is the part that matters. COOP alone leaves a same-origin popup readable, and the comment says so. The tests pin sandbox, nosniff and frame-ancestors 'none' (studioServer.unknownPaths.test.ts:57-75), so dropping one of them fails CI.
  • The claim that 13 of 16 tests fail on main holds. With main's studioServer.ts swapped in, I get 13 failed and 3 passed.
  • serviceWorker.register('/api/projects/project/preview/sw.js') from project script is refused (createStudioApi → refuseServiceWorkerScripts). So a worker can't sit in front of a project path and catch the return before this middleware sees it.
  • Studio routes by hash only (useStudioUrlState.ts:92, useServerConnection.ts:64). Nothing in studio, studio-server, core or player builds a code or state query, so serving the shell only at / and /index.html breaks no Studio link.

Blockers

  • Rule 2: preview still serves the Studio shell at /oauth/callback?code=… in its two Vite modes. preview.ts:591 (dev mode: CLI run from source, env.ts:5-8) and preview.ts:607 (local mode: the CLI's own @hyperframes/studio, or HYPERFRAMES_LOCAL_STUDIO=1, preview.ts:1567) both start the Vite server from packages/studio/vite.config.ts. That server uses Vite's default SPA fallback (vite.config.ts:388, no appType), and devProjectApi only guards /api/* and /__hyperframes_config (vite.config.ts:225). I ran vite from this head and fetched GET /oauth/callback?code=SECRET&state=s and GET /?code=SECRET. Both returned 200 text/html, the Studio shell, with no COOP and no sandbox.
    • Failure scenario: someone running the CLI from a monorepo checkout (HeyGen engineers, whose sessions are worth the most) runs preview on an untrusted project. Project script on the Vite origin opens app.heygen.com/oauth/authorize in a popup, with its own PKCE challenge and redirect_uri=http://127.0.0.1:<vite port>/oauth/callback. The backend accepts any loopback port and path for a public client (experiment-framework db/droplet/oauth2_models.py:69, :580-583). The authorize page sends no COOP and only frame-ancestors (checked live), so the opener keeps its handle and reads popup.location.href once the redirect lands on the shell.
    • The published npm CLI always runs embedded mode, so end users are covered. Fix: register the same refusal as the first server.middlewares.use in devProjectApi. It can reuse carriesOAuthReturn and the headers. Alternatively, descope it in the body with a tracked follow-up. The body's claim that preview serves the shell only at / and /index.html doesn't hold in those two modes.

Nits

  • Building on Rames's consolidation nit: the two copies have already drifted. This one adds Cross-Origin-Resource-Policy: same-origin and answers 400. The #8160 copy (utils/strayRequestRefusal.ts:6-14) has no CORP and answers 404. One shared header constant would keep the policy from drifting further.
  • The body says any other path gets the plain-text inert 404. That's true at the top level, but under /api/* the sub-app answers itself: /api/nope is a text/plain 404 with no sandbox, and a missing project file is a JSON 404. Neither carries a return, so this is wording only.
  • Residual, not this PR's to fix, but worth one line in the body as #8160 has: a return in the fragment (/#code=) never reaches the server. In Chrome, /#code= and /api/projects/project/preview/index.html#code= stay readable on this head. The code grant always answers in the query, but the backend still registers the implicit grant while its strict gate is off (heygen/domain/auth/logic/oauth2_server.py:191). Whether that can reach these servers depends on the CLI client's allowed response types, which is part 4's to close.
  • Tests: HEAD, OPTIONS, a trailing slash and a duplicate key behave correctly (above), but none of them is pinned. A browser regression like #8160's oauthReturn.browser.test.ts would pin the opaque-origin result the headers exist for.

CI: every required check passes at 9910e9eb (Build, Typecheck, Test, regression, Test: runtime contract, Test reachability, Render on windows-latest, Tests on windows-latest, Studio and player captures, Studio: edit accuracy gate, Semantic PR title). Skills: manifest in sync was skipped. The only pending check is the draft-mode WIP check.

Verdict: REQUEST CHANGES
Reasoning: The embedded preview fix is correct and holds in Chrome: all 12 query-return reads that succeed on main are blocked here. But preview's Vite-served dev and local modes still hand the shell to /oauth/callback?code=, with no COOP or sandbox. Cover them with the same middleware, or explicitly descope them with a ticket, and this is an approve.

@Vitozhu04

Copy link
Copy Markdown
Collaborator Author

@miguel-heygen thanks. I addressed the blocker in c8c0ac8b4.

  • Vite modes: devProjectApi in packages/studio/vite.config.ts now refuses a code or state at any path as its first middleware, before every route and Vite's own SPA fallback. It sends the same inert 400 as the embedded server: text/plain, sandbox; default-src 'none'; frame-ancestors 'none', COOP same-origin, nosniff, and a fixed body. Unknown paths in those modes still reach Vite, which serves source modules at many paths, so they get the return refusal but no path allowlist.
  • One helper: the refusal moved to @hyperframes/studio-server (helpers/inertRefusal.ts). The embedded server and the Vite modes now share one header set.
  • Fails without the fix: packages/studio/vite.config.hosts.test.ts › "studio dev server OAuth returns". It covers /oauth/callback, /callback, /, /index.html and /api/projects/project/preview with code or state. All 5 fail without the middleware: the page routes get expected undefined to be 400 (they pass through to Vite's fallback), and the preview route gets expected 200 to be 400. A plain /?hf_canary_… still passes through.
  • Nits: the PR body now records the drift from fix(cli): play and present answer unknown paths with an inert refusal #8160's copy (404, no CORP), with a follow-up to move fix(cli): play and present answer unknown paths with an inert refusal #8160 onto this helper once both land. It also has the /api/* 404 wording and a "Residual" note on fragment returns (/#code=), which is part 4's to close. I didn't add a browser regression test in this PR. Your Chrome run covers 9910e9eb; I have not run a browser against the Vite modes.

Tests at c8c0ac8b4: studio-server 2154, Studio vite.* 89, CLI src/server + src/auth 413, all passing. tsc is clean for the three packages and the comment ratchet passes.

🤖 Addressed by Claude Code

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at c8c0ac8b483cec3dc6b6ba264c8772de1fcd3fca.

Re-review of the delta from 9910e9eb. The Vite-mode gap raised by @miguel-heygen is resolved: both source-dev and local-Studio launch paths use this config, and its first middleware refuses query returns before API/runtime/config handlers and Vite's SPA fallback. Embedded preview retains the same fixed body and security headers through the shared studio-server helper. The Vite source import and built CLI export both resolve correctly.

Validation: bun run build passed. Through pytest-gate.sh, Studio's vite.config.hosts.test.ts passed 12/12, and CLI unknown-path/static-asset/auth tests passed 250/250. Removing only the new Vite middleware makes all five new refusal cases fail (5 failed, 7 passed); restoring it passes 12/12. A real Vite server also passed 24 HTTP refusal probes across GET/HEAD/OPTIONS/POST, including encoded keys, repeated/empty values, API and asset paths, plus a successful ordinary shell control. The server emitted dependency-scan cancellation messages during intentional shutdown, after the assertions passed. No live OAuth or browser popup flow was run in this round. Independent adversarial source audit found no introduced blocker.

The existing follow-up to consolidate play/present's refusal remains appropriate. Fragment-only returns remain outside this server-side query mitigation.

Need: yes · Size: ok · Reuse: shared studio-server refusal and existing response bridge · Simpler: already minimal · Structure: fine (checked embedded and Vite boundaries; shared policy removes duplication)
Risk: medium — local browser security boundary.

Verdict: APPROVE
Reasoning: The previously uncovered Vite launch modes now enforce the same query-return boundary, and the regression demonstrably fails without that middleware.

— Rames / hf-review

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at c8c0ac8b, against main. This follows my change request at 9910e9eb. The one commit since then covers the blocker, and Rames has approved at this head.

What changed and holds up

  • Both Vite modes now refuse a return. devProjectApi registers the refusal as its first server.middlewares.use (packages/studio/vite.config.ts:224-228). Plugin configureServer middleware runs before Vite's own stack, so a request carrying code or state gets the inert 400 before the host check, /api/*, /__hyperframes_config and the SPA fallback. devProjectApi is the only plugin here that adds middleware (vite.config.ts:364).
  • One helper, no drift between the two servers. studio-server/src/helpers/inertRefusal.ts now holds the headers, carriesOAuthReturn and refuseOAuthReturn. The embedded server (studioServer.ts:1001-1003) and the Vite config both import it, and the CLI's own copy is gone. Local mode needs vite.config.ts on disk (preview.ts:1566), and the published @hyperframes/studio ships only src and dist, so the relative import into ../studio-server/src always resolves where that config runs. That's the same pattern as the existing requestIdentity import.
  • Pinned. vite.config.hosts.test.ts sends five returns (/oauth/callback, /callback, /, /index.html?state=, a project preview path) through the plugin's middlewares, and asserts the 400 status, sandbox, frame-ancestors 'none', COOP, nosniff and no echo. A plain entry request still passes to Vite. Rames reports five failures with the middleware removed.

Nits (carried over, not blocking)

  • The #8160 copy (utils/strayRequestRefusal.ts) still answers 404 with no CORP. Pointing it at this helper would finish the consolidation.
  • A return in the fragment never reaches either server. Closing that is part 4's job.

Not run locally: the tests and a live Vite run at this head. I ran Vite at 9910e9eb to find the gap, and the new tests pin the fix.

CI: At c8c0ac8b, all 57 checks that ran pass, including Build, Typecheck, Test (cli, studio, runtime), regression, the Windows suites, Studio edit accuracy and CodeQL. 12 are skipped by path, and none fails or is pending. It merges cleanly into the current main.

Verdict: APPROVE
Reasoning: The Vite-served dev and local modes now refuse a query return through the same helper as the embedded server, ahead of the SPA fallback, and a test pins the headers. That clears the one blocker from my last review.

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes; details sent to you directly.

Vitozhu04 and others added 2 commits November 20, 2026 11:47
…e Studio shell

Studio routes by location.hash only, yet the preview server answered every
unknown GET with the Studio shell (200, same origin, query kept). An OAuth
redirect to the preview port (/oauth/callback?code=...&state=...) therefore
re-mounted the project, and project script read the code from the address.

The shell is now served only at / and /index.html. Any other path gets a
plain-text 404, and a request carrying `code` or `state` at any path (entry
and preview routes included) gets a plain-text 400. Both carry a sandbox CSP
(opaque origin), COOP same-origin, frame-ancestors 'none' / X-Frame-Options
DENY, nosniff, no-referrer and no-store, and never echo the request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`preview` from a source checkout (dev mode) and with the local studio
(HYPERFRAMES_LOCAL_STUDIO=1) run packages/studio/vite.config.ts, whose SPA
fallback served the Studio shell at /oauth/callback?code=... with no COOP or
sandbox. devProjectApi now refuses a `code` or `state` at any path as its
first middleware, with the same inert response as the embedded server.

The refusal moves to @hyperframes/studio-server so both servers share one
helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vitozhu04
Vitozhu04 force-pushed the claude/secops-2642-preview-catchall-a574f4 branch from c8c0ac8 to 966e802 Compare November 20, 2026 03:50
@Vitozhu04 Vitozhu04 changed the title fix(cli): preview answers unknown paths with an inert refusal, not the Studio shell (SECOPS-2642 part 1) fix(cli): preview answers unknown paths with an inert refusal, not the Studio shell Nov 20, 2026
@miguel-heygen
miguel-heygen dismissed their stale review November 20, 2026 03:53

reworded, thanks

@jerry-heygen jerry-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approval at 966e802239cb4472ea057e5fee119dfb475c3623.

What I checked first-hand:

  • The eight changed files, compared file by file between the previously approved head c8c0ac8b and this head, differ in five comment lines only (the internal ticket id removed from each). No code, test or config line differs.
  • The PR title, description and both commit messages at this head carry no internal ticket id.
  • I read the PR's own diff against main: the refusal runs as the first middleware before every route, the shell is served only at / and /index.html, every other path ends in the fixed plain-text 404, and the refusal body never reflects request input. That matches what the two earlier approvals at c8c0ac8b describe.
  • Workflow runs at this head: CI, CodeQL, regression, preview-regression, Windows render verification, Player perf and Comments completed with success. One PR captures run shows cancelled next to a successful one of the same name.

Not checked by me: nothing was run (no browser, no local server); I did not re-derive the earlier reviewers' browser findings.

Two things for the author: the PR is still marked draft, so it cannot merge until it is marked ready; and the earlier request for changes on the ticket ids shows as dismissed, so its author may want to confirm the wording at this head.

This is a technical re-approval of an unchanged change; the merge is the author's and the repo owners' step.

— Jerrai (cutroom-dev)

@Vitozhu04
Vitozhu04 marked this pull request as ready for review November 20, 2026 14:02
@Vitozhu04
Vitozhu04 added this pull request to the merge queue Nov 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 20, 2026
@Vitozhu04
Vitozhu04 added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 4e3c960 Nov 20, 2026
130 of 131 checks passed
@Vitozhu04
Vitozhu04 deleted the claude/secops-2642-preview-catchall-a574f4 branch November 20, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants